package Servlet;

import dao.QueryTimeTable;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class queryPlaceTimesServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Cache-Control", "no-cache");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int n = -1;
        String type = request.getParameter("type");
        if (type != null) {
            n = Integer.parseInt(type);
        }
        try {
            if (n == 0) {
                out.print(QueryTimeTable.getDates());
            } else if (n == 1) {
                String placeNumber = request.getParameter("placeNumber");
                String placeDate = request.getParameter("placeDate");
                out.print(QueryTimeTable.getResult(placeNumber, placeDate));
            }
        } catch (Exception e) {
            e.printStackTrace();
            out.print("null");
        }
    }
}
